
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :chengbiao.he
	CreateTime:2008-02-23 17:14:08
*/
public class CheckHeadSrv extends IHandler
{

	public CheckHeadSrv() 
	{
		super();
	}
	private void deleteCheckHead(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		CheckHead obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = CheckHead.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveCheckHead(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		CheckHead obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = CheckHead.fetch();
    	}
    	else                     //update
    	{
    		obj = CheckHead.fetch(con,id);
    	}
		CheckHeadPageData data = (CheckHeadPageData)PageData.fromForm(context,CheckHeadPageData.class);
		context.setValue("CheckHeadPageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listCheckHead(DBConnection con,SrvContext context,String path) throws Exception
	{
		CheckHeadSearchEvent event = (CheckHeadSearchEvent)SearchEvent.fromForm(context,CheckHeadSearchEvent.class);
		context.setSessionValue("CheckHeadSearchEvent",event);
		context.setNextUrl(path+"CheckHeadList.jsp");
	}
	private void backCheckHead(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"CheckHeadList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listCheckHead"))
		{
			listCheckHead(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewCheckHead"))
		{
			String id = context.getString("Id",null);
			CheckHead obj = CheckHead.fetch(con,id);
			context.setValue("CheckHead",obj);
			context.setNextUrl(path+"CheckHeadView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteCheckHead"))
		{
			context.setErrorUrl(path+"CheckHeadList.jsp");
			deleteCheckHead(con,context);
			backCheckHead(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddCheckHead"))
		{
			CheckHead obj = CheckHead.fetch();
			CheckHeadPageData data = (CheckHeadPageData)PageData.fromTable(obj,CheckHeadPageData.class);
			context.setValue("CheckHeadPageData",data);
			context.setNextUrl(path+"CheckHeadEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateCheckHead"))
		{
			String id = context.getString("Id",null);
			CheckHead obj = CheckHead.fetch(con,id);
			CheckHeadPageData data = (CheckHeadPageData)PageData.fromTable(obj,CheckHeadPageData.class);
			context.setValue("CheckHeadPageData",data);
			context.setNextUrl(path+"CheckHeadEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyCheckHead"))
		{
			String id = context.getString("Id",null);
			CheckHead obj = CheckHead.copy(CheckHead.fetch(con,id));
			CheckHeadPageData data = (CheckHeadPageData)PageData.fromTable(obj,CheckHeadPageData.class);
			context.setValue("CheckHeadPageData",data);
			context.setNextUrl(path+"CheckHeadEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveCheckHead"))
		{
			context.setErrorUrl(path+"CheckHeadEdit.jsp");
			saveCheckHead(con,context,loginContext);
			backCheckHead(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewCheckHead"))
		{
			context.setErrorUrl(path+"CheckHeadEdit.jsp");
			saveCheckHead(con,context,loginContext);
			CheckHead obj = CheckHead.fetch();
			CheckHeadPageData data = (CheckHeadPageData)PageData.fromTable(obj,CheckHeadPageData.class);
			context.setValue("CheckHeadPageData",data);
			context.setNextUrl(path+"CheckHeadEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListCheckHead"))
		{
			backCheckHead(con,context,path);
			return;
		}
		
		//add by chengbiao.he start

		//add by chengbiao.he end

		Logger.throwException("CheckHeadSrv","unknown action_code="+action_code);
	}
}
